﻿using LD.Host;
using LD.Host.项目;
using System;

namespace LD.Tool
{
    public partial class ToolScrewFrm : FrmToolBaseSkip// FrmToolBase
    {
        public ToolScrewFrm()
        {
            InitializeComponent();
            this.Shown += ToolMesSharpFrm_Shown;
            this.btn_ok.Click += Btn_ok_Click;
        }

        private void ToolMesSharpFrm_Shown(object sender, EventArgs e)
        {
            Init();
        }

        private void Init()
        {
            foreach (var item in CommunicateFactory.Instance.GetList)
            {
                this.cob_com.Items.Add(item.Name);
            }
            if (TB_Tool.Param != null)
            {
                var param = Newtonsoft.Json.JsonConvert.DeserializeObject<ToolScrewParame>(TB_Tool.Param);
                if (param != null)
                {
                    this.txt_barcode.Text = param.AdrBarcode;
                    this.num_slot.ValueNumber = param.Slot;
                    this.txt_adrNum.Text = param.AdrScrewNum;
                    this.txt_isLast.Text = param.AdrScrewLast;
                    this.txt_adrResult.Text = param.AdrResult;
                    this.txt_adrComplete.Text = param.AdrScrewComplete;
                    this.cob_com.Text = param.MobsRtu;
                    this.txt_start.Text = param.AdrStarted;
                }
            }
        }

        private void Btn_ok_Click(object sender, EventArgs e)
        {
            var param = new ToolScrewParame()
            {
                AdrBarcode = this.txt_barcode.Text,
                Slot = (int)this.num_slot.ValueNumber,
                AdrScrewNum = this.txt_adrNum.Text,
                AdrScrewLast = this.txt_isLast.Text,
                AdrResult = this.txt_adrResult.Text,
                AdrScrewComplete = this.txt_adrComplete.Text,
                MobsRtu = this.cob_com.Text,
                AdrStarted = this.txt_start.Text
            };

            TB_Tool.Param = Newtonsoft.Json.JsonConvert.SerializeObject(param);
        }
    }
}
